package com.ds.bar;

import com.ds.common.JDSException;
import com.ds.dsm.admin.temp.JavaTempNavTree;
import com.ds.enums.IconEnumstype;

import com.ds.esd.custom.nav.annotation.TabsAnnotation;
import com.ds.esd.custom.tree.annotation.TreeAnnotation;
import com.ds.esd.dsm.domain.enums.*;
import com.ds.esd.dsm.enums.DSMType;
import com.ds.esd.dsm.enums.RepositoryType;
import com.ds.esd.tool.ui.component.list.TreeListItem;
import com.ds.web.annotation.AggregationType;
import com.ds.web.annotation.ViewGroupType;
import com.ds.web.annotation.ViewType;

import java.util.Set;

@TabsAnnotation(singleOpen = true)
@TreeAnnotation(heplBar = true, caption = "出码方案")
public class CodeGenTempItem extends TreeListItem {


    public CodeGenTempItem() throws JDSException {
        this.caption = "模板分类";
        this.id = "AllTempGallery";
        this.className = "dsm.admin.temp.AllTempGrid";
        this.iniFold = false;
        this.imageClass = "spafont spa-icon-settingprj";
        DSMType[] dsmTypes = DSMType.getCustomTypes();
        for (DSMType dsmType : dsmTypes) {
            CodeGenTempItem domainInstTree = new CodeGenTempItem(dsmType);
            this.addChild(domainInstTree);
        }
        this.addTagVar("dsmType", DSMType.all.getType());
    }

    public CodeGenTempItem(DSMType dsmType) throws JDSException {
        this.caption = dsmType.getName();
        this.imageClass = dsmType.getImageClass();
        this.className = "dsm.admin.temp.CodeTempGrid";
        this.iniFold = false;
        this.id = dsmType.getType();
        this.addTagVar("dsmType", dsmType.getType());

        if (dsmType.equals(DSMType.aggregation)) {
            this.className = "dsm.admin.temp.agg.AllTempGrid";
            AggregationType[] aggregationTypes = AggregationType.values();
            for (AggregationType type : aggregationTypes) {

                this.addChild(new CodeGenTempItem(type));

            }

        } else if (dsmType.equals(DSMType.repository)) {
            this.className = "dsm.admin.temp." + DSMType.repository.getType() + ".AllTempGrid";
            RepositoryType[] repositoryTypes = RepositoryType.values();
            for (RepositoryType type : repositoryTypes) {

                this.addChild(new CodeGenTempItem(type));

            }
        } else if (dsmType.equals(DSMType.customDomain)) {
            this.className = "dsm.admin.temp.domain.AllTempGrid";
            CustomDomainType[] repositoryTypes = CustomDomainType.values();
            for (CustomDomainType type : repositoryTypes) {
                this.addChild(new CodeGenTempItem(type));
            }
        } else if (dsmType.equals(DSMType.view)) {
            this.className = "dsm.admin.temp." + DSMType.view.getType() + ".AllTempGrid";
            ViewGroupType[] viewTypes = ViewGroupType.values();
            for (ViewGroupType type : viewTypes) {
                Set<ViewType> viewTypeSet = ViewType.getGroupView(type);
                if (viewTypeSet.size() > 1) {
                    this.addChild(new CodeGenTempItem(type));
                } else if (viewTypeSet.size() > 0) {
                    this.addChild(new CodeGenTempItem(viewTypeSet.iterator().next()));
                }

            }
        }
    }

    public CodeGenTempItem(CustomDomainType customDomainType) throws JDSException {
        this.caption = customDomainType.getName();
        this.imageClass = customDomainType.getImageClass();
        this.id = DSMType.customDomain.getType() + "_" + customDomainType.getType();

        this.addTagVar("dsmType", DSMType.customDomain.getType());
        this.addTagVar("customDomainType", customDomainType.getType());

        switch (customDomainType) {
            case bpm:
                BpmDomainType[] types = BpmDomainType.values();
                this.className = "dsm.admin.temp.bpm.AllTempGrid";
                for (BpmDomainType type : types) {
                    this.addChild(new JavaTempNavTree(type,customDomainType));
                }
                break;
            case msg:
                MsgDomainType[] msgtypes = MsgDomainType.values();
                this.className = "dsm.admin.temp.msg.AllTempGrid";
                for (MsgDomainType type : msgtypes) {
                    this.addChild(new CodeGenTempItem(customDomainType, type));
                }
                break;
            case org:
                OrgDomainType[] orgtypes = OrgDomainType.values();
                this.className = "dsm.admin.temp.org.AllTempGrid";
                for (OrgDomainType type : orgtypes) {
                    this.addChild(new JavaTempNavTree(type,customDomainType));
                }
                break;
            case nav:
                NavDomainType[] navtypes = NavDomainType.values();
                this.className = "dsm.admin.temp.nav.AllTempGrid";
                for (NavDomainType type : navtypes) {
                    this.addChild(new CodeGenTempItem(customDomainType, type));
                }
                break;
            case vfs:
                VfsDomainType[] vfstypes = VfsDomainType.values();
                this.className = "dsm.admin.temp.vfs.AllTempGrid";
                for (VfsDomainType type : vfstypes) {
                    this.addChild(new CodeGenTempItem(customDomainType, type));
                }
                break;
        }

    }

    public CodeGenTempItem(AggregationType aggregationType) throws JDSException {
        this.caption = aggregationType.getName();
        this.imageClass = aggregationType.getImageClass();
        this.id = DSMType.aggregation.getType() + "_" + aggregationType.getType();
        this.className = "dsm.admin.temp.agg.TempGrid";
        this.addTagVar("dsmType", DSMType.aggregation.getType());
        this.addTagVar("aggregationType", aggregationType.getType());
    }

    public CodeGenTempItem(RepositoryType repositoryType) throws JDSException {
        this.caption = repositoryType.getName();
        this.imageClass = repositoryType.getImageClass();
        this.id = DSMType.repository.getType() + "_" + repositoryType.getType();
        this.className = "dsm.admin.temp." + DSMType.repository.getType() + ".TempGrid";
        this.addTagVar("dsmType", DSMType.repository.getType());
        this.addTagVar("repositoryType", repositoryType.getType());
    }


    public CodeGenTempItem(CustomDomainType customDomainType, IconEnumstype domainType) throws JDSException {
        this.caption = domainType.getName();
        this.imageClass = domainType.getImageClass();
        this.id = DSMType.customDomain.getType() + "_" + customDomainType.getType() + "_" + domainType.getType();
        this.className = "dsm.admin.temp." + customDomainType.getType() + ".AllTempGrid";
        this.addTagVar("dsmType", DSMType.customDomain.getType());
        this.addTagVar("customDomainType", customDomainType.getType());
        this.addTagVar("domainType", domainType.getType());
    }


    public CodeGenTempItem(ViewType viewType) throws JDSException {
        this.caption = viewType.getName();
        this.imageClass = viewType.getImageClass();
        this.id = DSMType.view.getType() + "_" + viewType.getType();
        this.className = "dsm.admin.temp." + DSMType.view.getType() + ".TempGrid";
        this.addTagVar("dsmType", DSMType.view.getType());
        this.addTagVar("viewType", viewType.getType());
    }

    public CodeGenTempItem(ViewGroupType groupType) throws JDSException {
        this.caption = groupType.getName();
        this.imageClass = groupType.getImageClass();
        this.id = DSMType.view.getType() + "_" + groupType.getType();

        for (ViewType type : ViewType.getGroupView(groupType)) {
            this.addChild(new CodeGenTempItem(type));
        }
        this.className = "dsm.admin.temp." + DSMType.view.getType() + ".TempGrid";
        this.addTagVar("dsmType", DSMType.view.getType());
        this.addTagVar("ViewGroupType", groupType.getType());
    }

}
